package android.kryten.detail;

import java.text.SimpleDateFormat;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.kryten.R;
import android.kryten.model.Objective;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ObjectiveDetail extends Dialog implements android.view.View.OnClickListener {

    private static final String TAG = "OBJECTIVE_DETAIL";
    
    private TextView tvAuthor;
    private TextView tvDescription;
    private TextView tvDate;
    
    /**
     * @param context
     */
    public ObjectiveDetail(Context context) {
        super(context);
        setContentView(R.layout.dlg_objective_detail);
               
        //get all views       
        tvDate = (TextView)findViewById(R.id.dlg_objective_date);
        tvAuthor = (TextView)findViewById(R.id.dlg_objective_author);
        tvDescription = (TextView)findViewById(R.id.dlg_objective_description);
       
        //handle click
        Button ok = (Button)findViewById(R.id.dlg_objective_detail_btn_ok);         
        ok.setOnClickListener(this);
    } 
    
    
    public void setObjectiveDetail(Objective objective) {
        //set values
    	SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    	        
//        tvDate.setText(String.valueOf(objective.getCreationDate()));
        if(objective.getAuthor().getLastName()!=null && objective.getAuthor().getLastName()!=null) {
        	tvAuthor.setText(objective.getAuthor().getLastName() + " " + objective.getAuthor().getFirstName());
        }
        tvDescription.setText(objective.getDescription());
        
        //load thumbnail in background - p��klad pro obr�zek viz n� EXAMPLE FOR PICTURES
        //new LoadThumbTask().execute( ... objective.getImage ...);
    } 


    /* (non-Javadoc)
     * @see android.view.View.OnClickListener#onClick(android.view.View)
     */
    public void onClick(View v) {
        dismiss(); //dismiss dialog        
    }
       
    
    /* --- EXAMPLE FOR PICTURES
    
    private final class LoadThumbTask extends AsyncTask<String, Void, Bitmap> {

       
        protected Bitmap doInBackground(String... params) {
           if (params != null && params.length > 0 && params[0] != null && params[0].trim().length() > 0) {
               
               try {
                   Log.i(TAG, "Load thumbnail from url:"+params[0]);
                   //load image from web
                   HttpClient cli = new DefaultHttpClient();
                   HttpGet get = new HttpGet(params[0]);
                   HttpResponse resp = cli.execute(get);
                   return BitmapFactory.decodeStream(resp.getEntity().getContent());
               } catch (Exception e) {
                   Log.e(TAG, "Error loading thumbnail" ,e);
               }
           }
           return null;
        }

       
        @Override
        protected void onPostExecute(Bitmap result) {
            if (result != null) {
                //set image to view 
                if (DetailDialog.this.isShowing())
                    imThumb.setImageBitmap(result);
            }
            
        }
        
        
    }  ------------- */

}